You are here: Symbol Reference > Dew Namespace > Dew.Math Namespace > Classes > TMtxVec Class > TMtxVec Methods > BinarySearch Method > TMtxVec.BinarySearch Method ([In] double, int)
Dew Math for .NET
ContentsIndexHome
PreviousUpNext
TMtxVec.BinarySearch Method ([In] double, int)

Finds exact or closest index match for X in sorted object values using binary search.

Syntax
C#
Visual Basic
public bool BinarySearch([In] double x, ref int XIndex);

True and exact index in XIndex, if found and False and the index of the next bigger or smaller value in XIndex, if not found.

The data in the vector must be sorted in ascending order for this function to work correctly. The closest match is the index of first bigger or smaller value in the array. 

To ensure bigger value write: 

 

Data := [0,2,3]; Data.BinarySearch(Value, XIndex); if Data[XIndex] > Value then Dec(XIndex);

 

To ensure smaller value write: 

 

Data := [0,2,3]; Data.BinarySearch(1, XIndex); if Data[XIndex] < Value then Inc(XIndex);
Copyright (c) 1999-2024 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!